﻿using System.Data;
using System.Data.SqlClient;
using Microsoft.Extensions.Options;
using Kingzad.MicroService.BusinessCore.Models.Options;

namespace Kingzad.MicroService.BusinessCore.Providers
{
    public interface ISqlConnectionFactory
    {
        IDbConnection GetConnection();
    }
    public class SqlConnectionFactory : ISqlConnectionFactory
    {
        private readonly IOptions<Connections> _connections;
        public SqlConnectionFactory(IOptions<Connections> connections)
        {
            _connections = connections;
        }

        public IDbConnection GetConnection()
        {
            return new SqlConnection(_connections.Value.SqlConnection);
        }
    }
}
